package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.mapper.TravelCommendMapper;
import cn.wolfcode.luowowo.article.query.TravelCommendQuery;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService {

    @Autowired
    private TravelCommendMapper commendMapper;

    @Override
    public PageInfo query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<TravelCommend> list = commendMapper.selectAll();
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if(travelCommend.getId()==null){
            commendMapper.insert(travelCommend);
        }else {
            commendMapper.updateByPrimaryKey(travelCommend);
        }
    }

    @Override
    public void delete(Long id) {
        commendMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<TravelCommend> getTop5() {
        List<TravelCommend> list = new ArrayList<>();
        list = commendMapper.getTop5();
        return list;
    }

}
